<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>树莓派搭建 【优雅の博客】 | 啊粥啊周舟の部落阁</title><meta name="author" content="Zhouwy"><meta name="copyright" content="Zhouwy"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="树莓派搭建 【优雅の博客】一、安装基本环境1.1 安装树莓派系统（这里推荐Raspberry）官网地址：https:&#x2F;&#x2F;www.raspberrypi.org&#x2F;software&#x2F;  新手推荐这个带桌面的版本。 由于某些众所周知的原因，如果不能科学上网，那么下载速度是这样的：  这里推荐几个国内下载源：  TUNA 镜像站（位于北京）：https:&#x2F;&#x2F;mirrors.tuna.tsinghua.ed">
<meta property="og:type" content="article">
<meta property="og:title" content="树莓派搭建 【优雅の博客】">
<meta property="og:url" content="https://gitee.com/zwyywz/zwyywz.git/2019/09/07/%E6%A0%91%E8%8E%93%E6%B4%BE%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/index.html">
<meta property="og:site_name" content="啊粥啊周舟の部落阁">
<meta property="og:description" content="树莓派搭建 【优雅の博客】一、安装基本环境1.1 安装树莓派系统（这里推荐Raspberry）官网地址：https:&#x2F;&#x2F;www.raspberrypi.org&#x2F;software&#x2F;  新手推荐这个带桌面的版本。 由于某些众所周知的原因，如果不能科学上网，那么下载速度是这样的：  这里推荐几个国内下载源：  TUNA 镜像站（位于北京）：https:&#x2F;&#x2F;mirrors.tuna.tsinghua.ed">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/Raspberry_Pi_4.jpg">
<meta property="article:published_time" content="2019-09-07T01:25:00.000Z">
<meta property="article:modified_time" content="2023-04-16T13:03:08.741Z">
<meta property="article:author" content="Zhouwy">
<meta property="article:tag" content="Typora">
<meta property="article:tag" content="Markdown">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/Raspberry_Pi_4.jpg"><link rel="shortcut icon" href="/zwyywz/img/favicon.png"><link rel="canonical" href="https://gitee.com/zwyywz/zwyywz.git/2019/09/07/%E6%A0%91%E8%8E%93%E6%B4%BE%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/zwyywz/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/zwyywz/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Zhouwy","link":"链接: ","source":"来源: 啊粥啊周舟の部落阁","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '树莓派搭建 【优雅の博客】',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-04-16 21:03:08'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="///at.alicdn.com/t/c/font_4018630_wl3l75i04vl.css"><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/zwyywz/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/zwyywz/archives/"><div class="headline">文章</div><div class="length-num">17</div></a><a href="/zwyywz/tags/"><div class="headline">标签</div><div class="length-num">29</div></a><a href="/zwyywz/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://blog-1300216920.cos.ap-nanjing.myqcloud.com/Raspberry_Pi_4.jpg')"><nav id="nav"><span id="blog-info"><a href="/zwyywz/" title="啊粥啊周舟の部落阁"><span class="site-name">啊粥啊周舟の部落阁</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zwyywz/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分类</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/note/"><i class="fa-fw iconfont icon-xuexibiji"></i><span> 学习笔记</span></a></li><li><a class="site-page child" href="/zwyywz/opensource/"><i class="fa-fw iconfont icon-xiangmu"></i><span> 开源项目</span></a></li><li><a class="site-page child" href="/zwyywz/development/"><i class="fa-fw iconfont icon-peizhi-xitongpeizhi"></i><span> 环境配置</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/zwyywz/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/zwyywz/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/zwyywz/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/zwyywz/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">树莓派搭建 【优雅の博客】</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-09-07T01:25:00.000Z" title="发表于 2019-09-07 09:25:00">2019-09-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-16T13:03:08.741Z" title="更新于 2023-04-16 21:03:08">2023-04-16</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="树莓派搭建 【优雅の博客】"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="树莓派搭建-【优雅の博客】"><a href="#树莓派搭建-【优雅の博客】" class="headerlink" title="树莓派搭建 【优雅の博客】"></a>树莓派搭建 【优雅の博客】</h1><h2 id="一、安装基本环境"><a href="#一、安装基本环境" class="headerlink" title="一、安装基本环境"></a>一、安装基本环境</h2><h3 id="1-1-安装树莓派系统（这里推荐Raspberry）"><a href="#1-1-安装树莓派系统（这里推荐Raspberry）" class="headerlink" title="1.1 安装树莓派系统（这里推荐Raspberry）"></a>1.1 安装树莓派系统（这里推荐Raspberry）</h3><p>官网地址：<a target="_blank" rel="noopener" href="https://www.raspberrypi.org/software/">https://www.raspberrypi.org/software/</a></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/2.png" alt=""></p>
<p>新手推荐这个带桌面的版本。</p>
<p>由于某些众所周知的原因，如果不能科学上网，那么下载速度是这样的：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/3.png" alt=""></p>
<p>这里推荐几个国内下载源：</p>
<ul>
<li>TUNA 镜像站（位于北京）：<a target="_blank" rel="noopener" href="https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/">https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/</a></li>
<li>SJTUG 镜像站（位于上海）：<a target="_blank" rel="noopener" href="https://mirrors.sjtug.sjtu.edu.cn/raspberry-pi-os-images/">https://mirrors.sjtug.sjtu.edu.cn/raspberry-pi-os-images/</a></li>
</ul>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/4.png" alt=""></p>
<p>写盘工具有很多，这里推荐<a target="_blank" rel="noopener" href="https://www.balena.io/etcher/">Etcher</a>,比较靠谱。target一定要选择SD卡，千万别选错！！！</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/6.png" alt=""></p>
<p>如果想采用ssh连接树莓派，还需在写制作好的SD卡（<strong>即写盘完成后电脑上会出现的boot分区，如果没有，拔下读卡器重插一下</strong>）中加入两个文件，一个是空白的ssh文件（即新建文本文档，将文件名改为ssh，<strong>去掉后缀名</strong>，<strong>去掉后缀名</strong>，<strong>去掉后缀名</strong>），再有就是wifi配置文件，文件名为wpa_supplicant.conf。内容如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">country=CN</span><br><span class="line">ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev</span><br><span class="line">update_config=1</span><br><span class="line"></span><br><span class="line">network=&#123;</span><br><span class="line">	ssid=&quot;zwy&quot;      </span><br><span class="line">	psk=&quot;12345678&quot;</span><br><span class="line">	priority=5</span><br><span class="line">&#125;</span><br><span class="line">network=&#123;</span><br><span class="line">	ssid=&quot;YiyaYiya&quot;</span><br><span class="line">	psk=&quot;lsluhiiin6103&quot;</span><br><span class="line">	priority=4</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>ssid:wifi名称</p>
<p>psk:wifi密码</p>
<p>priority:连接优先级</p>
<p>然后，将SD卡插回树莓派上就能正常开机了。不过这里有个巨坑。</p>
<hr>
<p><em>树莓派4b的typeC口由于设计问题，使用非官方的充电器，很有可能没法开机，故而推荐官方充电器，如果实在没有，采用手机5V/3A充电器应该也可以（亲测华为mate系列的可以）</em></p>
<hr>
<h3 id="1-2-远程连接以及换源"><a href="#1-2-远程连接以及换源" class="headerlink" title="1.2 远程连接以及换源"></a>1.2 远程连接以及换源</h3><p>远程连接工具有很多，我使用的是xshell和xftp。如果是第一次接触linux系统，推荐使用远程桌面工具，不过也需先连接远程终端，安装xrdp工具，只需在命令行输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install xrdp  </span><br></pre></td></tr></table></figure>
<p>就可以愉快是使用远程桌面了。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/7.png" alt=""></p>
<p>输入默认账号：pi  默认密码：raspberry</p>
<p>连接后，更改配置，输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo raspi-config</span><br></pre></td></tr></table></figure>
<p>选择第一项，更改密码。</p>
<p>基本配置完成后，开始换源：</p>
<p>第一步，先备份源文件</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo <span class="built_in">cp</span> /etc/apt/sources.list /etc/apt/sources.list.bak </span><br><span class="line">sudo <span class="built_in">cp</span> /etc/apt/sources.list.d/raspi.list  </span><br><span class="line">etc/apt/sources.list.d/raspi.list.bak</span><br></pre></td></tr></table></figure>
<p>第二步，编辑系统源文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nano /etc/apt/sources.list</span><br></pre></td></tr></table></figure>
<p>第三步，将初始的源使用#注释掉，添加如下两行清华的镜像源。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi </span><br><span class="line">deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi</span><br></pre></td></tr></table></figure>
<p>第四步，保存执行如下命令 sudo apt-get update，完成源的更新软件包索引。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get update&amp;&amp;sudo apt-get upgrade</span><br></pre></td></tr></table></figure>
<p>第五步，还需要更改系统源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nano /etc/apt/sources.list.d/raspi.list</span><br></pre></td></tr></table></figure>
<p>用#注释掉原文件内容，用以下内容取代：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui</span><br></pre></td></tr></table></figure>
<p>更改pip源<br>新建~/.pip/pip.conf文件，写入其地址。阿里云、中科大、豆瓣等都有pip源。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[global]</span><br><span class="line">index-url = http://pypi.douban.com/simple/</span><br></pre></td></tr></table></figure>
<h2 id="二、相关软件配置"><a href="#二、相关软件配置" class="headerlink" title="二、相关软件配置"></a>二、相关软件配置</h2><h3 id="2-1-配置git"><a href="#2-1-配置git" class="headerlink" title="2.1 配置git"></a>2.1 配置git</h3><p>在树莓派终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install git</span><br></pre></td></tr></table></figure>
<p>在树莓派终端输入下列命令修改全局用户名（注意将引号内替换为个人帐号）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;你的GitHub/Gitee用户名&quot;</span><br><span class="line">git config --global user.email &quot;你的GitHub/Gitee邮箱&quot;</span><br></pre></td></tr></table></figure>
<p>然后查看是否已经全局修改用户名：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --list</span><br></pre></td></tr></table></figure>
<p>配置完成后如下图：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122174229788.png" alt=""></p>
<h3 id="2-2安装Node-js"><a href="#2-2安装Node-js" class="headerlink" title="2.2安装Node.js"></a>2.2安装Node.js</h3><p>首先查看树莓派的架构，树莓派终端输入命令:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uname -a</span><br></pre></td></tr></table></figure>
<p>我使用的树莓派4B是基于<code>armv7</code>架构，如图所示：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122174511028.png" alt=""></p>
<p>然后登录<a target="_blank" rel="noopener" href="https://nodejs.org/en/download/">Nood.js官网</a>，我们可以看到长期支持版是<code>14.15.4</code>，可自由选择版本，如下命令根据版本变化。</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122174646072.png" alt=""></p>
<p>在树莓派终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-armv7l.tar.xz</span><br></pre></td></tr></table></figure>
<p>如果出现下载缓慢的问题我们也可以使用国内开源镜像源(某宝源)下载：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget https://cdn.npm.taobao.org/dist/node/latest-v14.x/node-v14.15.4-linux-armv7l.tar.xz</span><br></pre></td></tr></table></figure>
<p>解压二进制包，在树莓派下输入如下命令：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xz -d node-v14.15.4-linux-armv7l.tar.xz &amp;&amp; tar -xavf node-v14.15.4-linux-armv7l.tar</span><br></pre></td></tr></table></figure>
<p>解压后，将二进制包移动到<code>/usr/local/node</code>下，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo mv ./node-v10.0.0-linux-armv7l /usr/local/node</span><br></pre></td></tr></table></figure>
<p>然后为<code>node</code>和<code>npm</code>建立软连接，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo ln -s /usr/local/node/bin/node /usr/bin/node</span><br><span class="line">sudo ln -s /usr/local/node/bin/npm /usr/bin/npm</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">这类似于Windows中的快捷方式</span></span><br></pre></td></tr></table></figure>
<p>我们通过查看<code>node</code>和<code>npm</code>版本的方式来查看是否成功，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">node -v &amp;&amp; npm -v</span><br></pre></td></tr></table></figure>
<p>至此我们完成了<code>hexo</code>博客两大准备工作<code>Git</code>和<code>Node.js</code>的配置，我们正式进入安装<code>hexo</code>博客框架。</p>
<h2 id="三、安装Hexo"><a href="#三、安装Hexo" class="headerlink" title="三、安装Hexo"></a>三、安装Hexo</h2><p>由于国内网速问题<code>npm</code>包管理器的速度会较慢，我们利用<code>npm</code>安装<code>cnpm</code>也就是前文提到的某宝源，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install -g cnpm --registry=https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure>
<p>同理我们为<code>cnpm</code>建立软连接，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ln -s /usr/local/node/bin/cnpm /usr/bin/cnpm</span><br></pre></td></tr></table></figure>
<p>安装Hexo博客框架，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cnpm install -g hexo-cli</span><br></pre></td></tr></table></figure>
<p>等待执行完，我们通过查看<code>hexo</code>版本的方式来查看是否成功，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo -v</span><br></pre></td></tr></table></figure>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122175725229.png" alt=""></p>
<h2 id="四、使用Hexo搭建博客"><a href="#四、使用Hexo搭建博客" class="headerlink" title="四、使用Hexo搭建博客"></a>四、使用Hexo搭建博客</h2><p>创建一个目录，作为博客的根目录，名字任取，这里取<code>blog</code>，并进入<code>blog</code>目录，在终端输入:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir blog</span><br><span class="line">cd blog</span><br></pre></td></tr></table></figure>
<p>初始化<code>Hexo</code>，在终端输入：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo hexo init</span><br></pre></td></tr></table></figure>
<p>启动<code>Hexo</code>，在终端输入：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo hexo s</span><br></pre></td></tr></table></figure>
<p>出现如下图提示后：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122180658511.png" alt=""></p>
<p>在浏览器输入：<code>树莓派IP:4000</code></p>
<p>可以看到我们的博客已经搭建完成了，如下图<code>hexo</code>自动生成了一篇<code>Hello World</code>的文章，文章内简介了<code>hexo</code>的用法，这里不再赘述，请仔细阅读。</p>
<p><img src="https://cdn.jsdelivr.net/gh/Fengweicui1996/CDN/4bnoodjs/11.png" alt=""></p>
<p>然后我们回到命令行按住<code>Ctrl+C</code>退出。所有文章均以<code>.md</code>格式保存在<code>/source/_posts</code>我们可以在此目录下删除或添加文章。</p>
<h2 id="五、将本地Hexo博客部署到远端Github"><a href="#五、将本地Hexo博客部署到远端Github" class="headerlink" title="五、将本地Hexo博客部署到远端Github"></a>五、将本地Hexo博客部署到远端Github</h2><p>我们在<code>github</code>上新建一个仓库<code>Create a new repository</code>，注意仓库名字必须为：</p>
<p> <strong>你的github账户名.github.io</strong></p>
<p>后面我们将用此名字作为域名访问博客。</p>
<p>回到树莓派终端，在博客根目录下，这是<code>/blog</code>目录下，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo cnpm install --save hexo-deployer-git</span><br></pre></td></tr></table></figure>
<p>然后我们需要配置博客根目录下的<code>_config.yml</code>文件，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nano _config.yml</span><br></pre></td></tr></table></figure>
<p>进入<code>_config.yml</code>后到文件末端，如下图<br>将此处修改为:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Deployment</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment"># Docs: https://hexo.io/docs/deployment.html</span></span></span><br><span class="line">deploy:</span><br><span class="line">  type: git</span><br><span class="line">  repo: https://github.com/你的账户名/你的账户名.github.io</span><br><span class="line">  branch: master</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">注意这里的冒号后要加空格</span></span><br></pre></td></tr></table></figure>
<p>按<code>Ctrl+X</code>退出，按<code>Y</code>保存<br>然后依次执行下列三条命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo hexo clean</span><br><span class="line">sudo hexo g</span><br><span class="line">sudo hexo s</span><br></pre></td></tr></table></figure>
<p>在树莓派本地浏览器输入如下端口查看本地预览: <code>localhost:4000</code></p>
<p>然后回到终端<code>Ctrl+C</code>退出，在终端输入：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo hexo d</span><br></pre></td></tr></table></figure>
<p>输入自己的<code>github</code>用户名跟密码，即可推送到<code>github</code>，我们可以输入如下域名查看个人博客。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">你的用户名.github.io</span><br></pre></td></tr></table></figure>
<p>每次写完博客都要重复这几个步骤。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo hexo d</span><br><span class="line">sudo hexo clean &amp;&amp; sudo hexo g &amp;&amp; sudo hexo s</span><br></pre></td></tr></table></figure>
<h2 id="六、Typora-PicGo-Github图床-优雅の博客"><a href="#六、Typora-PicGo-Github图床-优雅の博客" class="headerlink" title="六、Typora+PicGo+Github图床=优雅の博客"></a>六、Typora+PicGo+Github图床=优雅の博客</h2><blockquote>
<p>Typora 是一款<strong>支持实时预览的 Markdown 文本编辑器</strong>。它有 OS X、Windows、Linux 三个平台的版本，并且由于仍在测试中，是<strong>完全免费</strong>的</p>
<p>Typora 一直是我认为桌面端笔记应用应有的终极形态。用我之前 一篇文章 中的话来说就是，「它的<strong>功能之强大、设计之冷静、体验之美妙、理念之先进</strong>，我认为值得所有笔记应用厂商学习。</p>
</blockquote>
<p>首先安装<a target="_blank" rel="noopener" href="https://typora.io/#windows">typora</a>:</p>
<p>下载-&gt;next ….. next-&gt; 完成。:grin:</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122182557137.png" alt=""></p>
<p>下载完成后可以打开偏好设置：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122182654108.png" alt=""></p>
<p>图片-&gt;上传图片；上传服务-&gt;PicGo,然后点击下载PicGo,会跳转到PicGo的官网</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122182912371.png" alt=""></p>
<p>然后点击免费下载，要求版本<code>&gt;=2.2.0</code>且不推荐<code>beta</code>版,安装完成后，如图：</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122183822206.png" alt=""></p>
<p>接下来创建Github仓库；</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122183957578.png" alt=""></p>
<p>仓库名字：任意（如image、Img皆可）</p>
<p>切记：选择公开（Public）</p>
<p>接下来：获得Tokens密钥，网址为：<a target="_blank" rel="noopener" href="https://github.com/settings/tokens">https://github.com/settings/tokens</a></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122184357428.png" alt=""></p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122184558027.png" alt=""></p>
<p>然后配置PicGo,图床设置-&gt;GitHub图床</p>
<p><img src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/image-20210122194003722.png" alt=""></p>
<p>设置仓库名：<code>个人名称/刚刚新建的仓库</code></p>
<p>设置分支名：<code>master</code></p>
<p>设置Token:<code>刚刚获取的Token</code></p>
<hr>
<p>一起设置完成后；</p>
<p>大功告成！！！撒花<em>★,°</em>:.☆(￣▽￣)/$:<em>.°★</em> 。:happy:</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git">Zhouwy</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://gitee.com/zwyywz/zwyywz.git/2019/09/07/%E6%A0%91%E8%8E%93%E6%B4%BE%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/">https://gitee.com/zwyywz/zwyywz.git/2019/09/07/%E6%A0%91%E8%8E%93%E6%B4%BE%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://gitee.com/zwyywz/zwyywz.git" target="_blank">啊粥啊周舟の部落阁</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/zwyywz/tags/Typora/">Typora</a><a class="post-meta__tags" href="/zwyywz/tags/Markdown/">Markdown</a></div><div class="post_share"><div class="social-share" data-image="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/Raspberry_Pi_4.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/zwyywz/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/zwyywz/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/zwyywz/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/zwyywz/2019/09/07/%E5%8F%8C%E6%97%8B%E7%BF%BC%E9%A3%9E%E8%A1%8C%E5%99%A8/" title="升降式双旋翼飞行器"><img class="cover" src="https://blog-1300216920.cos.ap-nanjing.myqcloud.com/下载.jpg" onerror="onerror=null;src='/zwyywz/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">升降式双旋翼飞行器</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A0%91%E8%8E%93%E6%B4%BE%E6%90%AD%E5%BB%BA-%E3%80%90%E4%BC%98%E9%9B%85%E3%81%AE%E5%8D%9A%E5%AE%A2%E3%80%91"><span class="toc-number">1.</span> <span class="toc-text">树莓派搭建 【优雅の博客】</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%AE%89%E8%A3%85%E5%9F%BA%E6%9C%AC%E7%8E%AF%E5%A2%83"><span class="toc-number">1.1.</span> <span class="toc-text">一、安装基本环境</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-%E5%AE%89%E8%A3%85%E6%A0%91%E8%8E%93%E6%B4%BE%E7%B3%BB%E7%BB%9F%EF%BC%88%E8%BF%99%E9%87%8C%E6%8E%A8%E8%8D%90Raspberry%EF%BC%89"><span class="toc-number">1.1.1.</span> <span class="toc-text">1.1 安装树莓派系统（这里推荐Raspberry）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5%E4%BB%A5%E5%8F%8A%E6%8D%A2%E6%BA%90"><span class="toc-number">1.1.2.</span> <span class="toc-text">1.2 远程连接以及换源</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E7%9B%B8%E5%85%B3%E8%BD%AF%E4%BB%B6%E9%85%8D%E7%BD%AE"><span class="toc-number">1.2.</span> <span class="toc-text">二、相关软件配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E9%85%8D%E7%BD%AEgit"><span class="toc-number">1.2.1.</span> <span class="toc-text">2.1 配置git</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2%E5%AE%89%E8%A3%85Node-js"><span class="toc-number">1.2.2.</span> <span class="toc-text">2.2安装Node.js</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E5%AE%89%E8%A3%85Hexo"><span class="toc-number">1.3.</span> <span class="toc-text">三、安装Hexo</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E4%BD%BF%E7%94%A8Hexo%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2"><span class="toc-number">1.4.</span> <span class="toc-text">四、使用Hexo搭建博客</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E5%B0%86%E6%9C%AC%E5%9C%B0Hexo%E5%8D%9A%E5%AE%A2%E9%83%A8%E7%BD%B2%E5%88%B0%E8%BF%9C%E7%AB%AFGithub"><span class="toc-number">1.5.</span> <span class="toc-text">五、将本地Hexo博客部署到远端Github</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%AD%E3%80%81Typora-PicGo-Github%E5%9B%BE%E5%BA%8A-%E4%BC%98%E9%9B%85%E3%81%AE%E5%8D%9A%E5%AE%A2"><span class="toc-number">1.6.</span> <span class="toc-text">六、Typora+PicGo+Github图床&#x3D;优雅の博客</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Zhouwy</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/zwyywz/js/utils.js"></script><script src="/zwyywz/js/main.js"></script><script src="/zwyywz/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.1
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container').forEach(node => {
            if (node.hasAttribute('display')) {
              btf.wrap(node, 'div', { class: 'mathjax-overflow' })
            } else {
              btf.wrap(node, 'span', { class: 'mathjax-overflow' })
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax/es5/tex-mml-chtml.min.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typesetPromise()
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>